package server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;

import dataContracts.CommandParser;
import dataContracts.CommandType;

public class ClientConnection {
	String name;
	Socket socket;
	PrintWriter writer;
	BufferedReader reader;
	OutputStream binaryWriter;
	InputStream binaryReader;
	
	ClientConnection(Socket socket) throws IOException {
		this.socket = socket;
		writer = new PrintWriter(socket.getOutputStream());
		binaryWriter = socket.getOutputStream();
		binaryReader = socket.getInputStream();
		InputStreamReader inputReader = new InputStreamReader(socket.getInputStream());
		reader = new BufferedReader(inputReader);
	}
	
	public void notify(String message) {
		String msg = CommandParser.buildCommand(CommandType.Broadcast, message);
		writer.println(msg);
		writer.flush();
	}
	
	public void command(String message) {
		writer.println(message);
		writer.flush();
	}
	
	public String readLine() throws IOException {
		return this.reader.readLine();
	}
}
